package com.xueyiyue.xueyiyue.model.sys;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 通用api返回结果
 *
 * @author wenqi
 * @since v1.1
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class ApiResult {
    /**
     * 返回code
     * @see CodeSupport
     */
    private int code;
    /**
     * 接口返回说明
     */
    private String msg;
    /**
     * 额外数据
     */
    private Object body;

    public static ApiResult ok(String msg, Object data){
        return new ApiResult(CodeSupport.SUCCESS.getCode(),msg,data);
    }

    public static ApiResult ok(Object data){
        return ok("",data);
    }

    public static ApiResult ok(){
        return ok("",null);
    }

    public static ApiResult fail(String msg, Object data){
        return new ApiResult(CodeSupport.FAIL.getCode(),msg,data);
    }

    /**
     * 快捷构造 需要失败的原因，可以为空
     * @param msg 失败的原因
     * @return
     */
    public static ApiResult fail(String msg){
        return fail(msg,null);
    }

    public static ApiResult fail(){
        return fail(null);
    }

}
